package com.night.icm.controller.business;

import com.night.icm.common.utils.PageDataDTO;
import com.night.icm.common.utils.TermType;
import com.night.icm.model.business.StudentCourseGradeGatherDTO;
import com.night.icm.service.business.service.StudentCourseGradeGatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * StudentCourseGradeGatherController
 *
 * @author Liao ZhiYong
 * @date 2020/2/15
 */
@Api(tags = "学生课程成绩汇总")
@RestController
@RequestMapping("/api/icm-student-course-grade-grather")
public class StudentCourseGradeGatherController {

    private final StudentCourseGradeGatherService studentCourseGradeGatherService;

    @Autowired
    public StudentCourseGradeGatherController(StudentCourseGradeGatherService studentCourseGradeGatherService) {
        this.studentCourseGradeGatherService = studentCourseGradeGatherService;
    }

    @ApiOperation(value = "分页查询学生课程成绩汇总")
    @GetMapping(value = "")
    public PageDataDTO<StudentCourseGradeGatherDTO> findOnePage(
            @ApiParam(value = "页号，从0开始", required = true, defaultValue = "0") @RequestParam("page") @Min(0) int page,
            @ApiParam(value = "每页记录条数", required = true, defaultValue = "30") @RequestParam("size") @Min(1) @Max(100) int size,
            @ApiParam(value = "排序字段，例如：字段1,asc,字段2,desc") @RequestParam(value = "sort", required = false, defaultValue = "id,desc") String sort,
            @ApiParam(value = "学生id") @RequestParam(value = "studentId", required = false) String studentId,
            @ApiParam(value = "所属年度") @RequestParam(value = "year", required = false) String year,
            @ApiParam(value = "所属学期") @RequestParam(value = "termType", required = false) TermType termType
    ) {
        return this.studentCourseGradeGatherService.findOnePage(page, size, sort, studentId, year, termType);
    }

    @ApiOperation(value = "模糊查询学生课程成绩汇总")
    @GetMapping(value = "/search")
    public List<StudentCourseGradeGatherDTO> search(
            @ApiParam(value = "学生code") @RequestParam(value = "studentCode", required = false) String studentCode,
            @ApiParam(value = "所属年度") @RequestParam(value = "year", required = false) String year,
            @ApiParam(value = "所属学期") @RequestParam(value = "termType", required = false) TermType termType
    ) {
        return this.studentCourseGradeGatherService.search(studentCode, year, termType);
    }
}